package com.platform.car.controller;

import com.platform.car.model.City;
import com.platform.car.service.CityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.List;


/**
 * 城市管理 Controller
 * @author GaoXiang
 * @version 1.0
 */
@Controller
@RequestMapping("/city")
public class CityController {
    @Autowired
    private CityService cityService;

    /**
     * 选择市
     * @param request
     * @param name
     * @return
     */
    @RequestMapping(value = "/chooseCity")
    @ResponseBody
    public List<City>  chooseCity(HttpServletRequest request, @RequestParam String name){
        City city = cityService.selectByName(name);
        return  cityService.chooseNext(city.getId());
    }

    /**
     * 选择区
     * @param request
     * @param name
     * @return
     */
    @RequestMapping(value = "/chooseArea")
    @ResponseBody
    public List<City>  chooseArea(HttpServletRequest request, @RequestParam String name){
        Long id = cityService.selectByName(name).getId();
        return  cityService.chooseNext(id);
    }

    /**
     * 默认选择
     * @param request
     * @param name
     * @return
     */
    @RequestMapping(value = "/defaultNext")
    @ResponseBody
    public List<City> defaultNext(HttpServletRequest request, @RequestParam String name){
        Long id = cityService.selectByName(name).getId();
        return  cityService.chooseNext(id);
    }
}
